class Solution(object):
    def gridGame(self, grid):
        n = len(grid[0])
        for i in range(2):
            for j in range(1, n):
                grid[i][j] += grid[i][j - 1]
        max_val = grid[0][n - 1] - grid[0][0]
        for i in range(1, n):
            max_val = min(max_val, max(grid[0][n - 1] - grid[0][i], grid[1][i - 1]))
        return max_val
